/**
 * @Description: add指令
 * @author Beon
 * @date 2021/1/4
*/
import * as childProcess from 'child_process';
import {ErrorCatch} from '../decorators/errorCatch';
import '../utils/consoleColor';

export class Add{

    /**
     * 进行add .操作
     * @param {String} repoPath 执行路径
     * @returns {Promise<void>}
     */
    @ErrorCatch.errorNotice('自动add失败，请检查报错信息')
    static async addPath (repoPath?: string): Promise<void> {
        await childProcess.execSync('git add .', { cwd: repoPath });
    }

    /**
     * add指定文件或文件夹
     * @param {String} repoPath 执行路径
     * @param {String[]} filename add最后一个参数
     * @returns {Promise<void>}
     */
    @ErrorCatch.errorNotice('add文件失败，请检查报错信息')
    static async addFile (filename: string[], repoPath?: string): Promise<void> {
        await childProcess.execSync(`git add ${filename.join(' ')}`, { cwd: repoPath });
    }
}
